<template>
    <div>
        <div class="info-form">
            <el-button type="primary" @click="submitForm()" v-if="addForm.switch">新增</el-button>
        </div>
        <div>
            <el-table
                    :data="tableData"
                    stripe
                    style="width: 100%">
                <el-table-column
                        prop="examdescription"
                        label="考试名称">
                </el-table-column>
                <el-table-column
                        prop="examTime"
                        label="考试时间">
                </el-table-column>
                <el-table-column label="操作">
                    <template scope="scope">
                        <el-button @click="handleClick(scope.$index)" type="text" size="small">查看</el-button>
                        <!--<el-button @click.native.prevent="deleteRow(scope.$index, tableData)" type="text" size="small"> 删除-->

                        <!--</el-button>-->
                    </template>
                </el-table-column>
            </el-table>
            <el-dialog title="编辑时间" :visible.sync="dialogTableVisible">
                <el-table
                        :data="examData"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="lname"
                            label="考试科目">
                    </el-table-column>
                    <el-table-column
                            prop="examTime"
                            label="考试时间">
                    </el-table-column>
                    <el-table-column
                            prop="startTime"
                            label="开始时间">
                    </el-table-column>
                    <el-table-column
                            prop="endTime"
                            label="结束时间">
                    </el-table-column>
                </el-table>
            </el-dialog>
        </div>
    </div>
</template>

<script>
    import moment from 'moment';
    import ElFormItem from "../../../../node_modules/element-ui/packages/form/src/form-item";
    export default {
        components: {ElFormItem},
        data() {
            return {
                index: '',
                options: [],
                value: '',
                value1: '',
                value2: '',
                addForm: {},
                tableData: [],
                lessons: [],
                examData: [],
                dialogTableVisible: false,
                pickerOptions0: {
                    disabledDate(time) {
                        return time.getTime() < Date.now() - 8.64e7;
                    }
                },

            }
        },
        activated(){
            let user = JSON.parse(localStorage.getItem("currentUser"));
            if (user.account == "system") {
                this.addForm.switch = true;
            }
            this.getExam();

        },
        methods: {
            submitForm(){
                this.$router.push({
                    path: '/addexam',
//                    query: {item: this.tableData[index]}
                });

            },
            getExam(){
                let self = this;
                this.tableData = [];
                this.$axioxs.get("/exam/getDes")
                    .then(function (res) {
                        res.data.records.forEach(item => {
                            item.examTime = moment(item.examTime).format("YYYY-MM-DD");
//                            item.startTime = moment(item.startTime).format("hh:mm:ss");
//                            item.endTime = moment(item.endTime).format("hh:mm:ss");
                            self.tableData.push(item);
                        })
                    })
            },
            handleClick(index) {
                this.dialogTableVisible = true;
                let self = this;
                this.examData = [];
                let desid = this.tableData[index].examdescription_id;
                this.$axioxs.get("/exam/get?desid="+desid)
                    .then(function (res) {
                        res.data.records.forEach(item => {
                            item.examTime = moment(item.examTime).format("YYYY-MM-DD");
                            item.startTime = moment(item.startTime).format("hh:mm:ss");
                            item.endTime = moment(item.endTime).format("hh:mm:ss");
                            self.examData.push(item);
                        })
                    })
            },
            deleteRow(index, rows) {
                rows.splice(index, 1);
            }
        }
    }
</script>